home *** CD-ROM | disk | FTP | other *** search
/ CICA 1993 April / CICA MS Windows - April 1993.iso / unzipped / programr / vbasic / cmdlg2 / dialog.txt < prev    next >
Text File  |  1992-08-10  |  3KB  |  79 lines

  1. It has proved difficult to retrieve the printer Driver, DeviceName and Port
  2. combination selected using the MhPrintDlg%() function (without using the 'Def'
  3. version to change the default printer and using GetProgileStringto load the Windows,Device line)
  4.  
  5. However, with the help of the DIALOG.ZIP file uploaded by
  6. Costas Kitsos (73667,1755) we have derived the following: 
  7.  
  8. The DevNames data Structure contains the following items:
  9.  
  10.    wDriverOffset : Offset to start of DriverName e.g. 'Canon LPB-8 III'
  11.    wDeviceOffset : Offset to start of DeviceName e.g. 'LBPIII'
  12.    wOutputOffset : Offset to start of PortName e.g. 'LPT1'
  13.         wDefault : 1 if default printer choosen, 0 otherwise.
  14.  
  15. All offsets are relative to the base of the DevNames structure.
  16.  
  17. Maximum Sizes:
  18.         32 for device + nul
  19.          8 for driver + nul
  20.          4 for port + nul
  21. Total = 47 extra bytes
  22.  
  23. Type DevNames
  24.     wDriverOffset As Integer
  25.     wDeviceOffset As Integer
  26.     wOutputOffset As Integer
  27.     wDefault As Integer
  28.     cNames As String * 47
  29. End Type
  30.  
  31. Dim N As DevNames
  32. Dim P As MhPrintDlog
  33.  
  34. If P.hDevNames <> 0 Then
  35.     Address = GlobalLock(P.hDevNames)  ' Lock handle and obtain address
  36.     Call hmemcpy(N, ByVal Address, Len(N)) ' Copy to VB variable.
  37.     Ok = GlobalUnlock(P.hDevNames) ' Unlock handle.
  38.     ' The Memory used by the Devnames structure may be freed with
  39.     '
  40.     '    Ok = GlobalFree(P.hDevNames)
  41.     '
  42.     ' but if you call the the printer dialog again you need it 
  43.     ' to keep the settings currently in use
  44.  
  45.     ' Correct the offsets to to the base of the cNames string
  46.     N.wDeviceOffset = N.wDeviceOffset - 7
  47.     N.wDriverOffset = N.wDriverOffset - 7
  48.     N.wOutputOffset = N.wOutputOffset - 7
  49.     
  50.     lenDevice = N.wDriverOffset - N.wDeviceOffset - 1
  51.     lenDriver = N.wOutputOffset - N.wDriverOffset - 1
  52.     ' and retrieve the strings
  53.     PrnDevice$ = Mid$(N.cNames, N.wDeviceOffset, lenDevice)
  54.     PrnDriver$ = Mid$(N.cNames, N.wDriverOffset, lenDriver)
  55.     PrnPort$ = Mid$(N.cNames, N.wOutputOffset, 4)
  56. End If
  57.  
  58. The PrnDevice$,PrnDriver$ and PrnPort$ may then be used
  59. with CreateDC to generate a Printer device context whenever
  60. printing is required. (Without presenting the common dialog):
  61.  
  62.     In Global module:
  63.     Declare Function CreateDC Lib "GDI" (ByVal lpDriverName As String, ByVal 
  64. lpDeviceName As String, ByVal lpOutput As String,ByVal pInitData As String) As 
  65. Integer
  66.         Declare Function DeleteDC Lib "GDI" (ByVal hDC As Integer) As Integer
  67.  
  68.     Where printing required:
  69.  
  70.         hDC = CreateDC(PrnDevice$, PrnDriver$, PrnPort$, hDevMode)
  71.         '
  72.         ' StartDoc Escape
  73.         '    For each page:
  74.         '        API Printing calls...
  75.         '        NewPage Escape 
  76.         ' EndDoc Escape
  77.         lOk = DeleteDC(hDC)
  78.  
  79.